package com.prs.crm.action.official;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.BaseAction;
import org.courser.ui.PaginationSupport;
import org.hibernate.criterion.DetachedCriteria;

import com.prs.crm.domain.official.DeptMailAutograph;
import com.prs.crm.domain.official.PersonalMailAutograph;
import com.prs.crm.service.official.DeptMailAutographService;
import com.prs.crm.service.official.PersonalMailAutographService;

public class PersonalMailAutographAction extends BaseAction{

	private static final long serialVersionUID = 1L;
	private Integer[] ids;
	private PaginationSupport pagination;
	private PersonalMailAutograph personalMailAutograph;
	private PersonalMailAutographService personalMailAutographService;
	public Integer[] getIds() {
		return ids;
	}
	public void setIds(Integer[] ids) {
		this.ids = ids;
	}
	public PaginationSupport getPagination() {
		return pagination;
	}
	public void setPagination(PaginationSupport pagination) {
		this.pagination = pagination;
	}

	public PersonalMailAutograph getPersonalMailAutograph() {
		return personalMailAutograph;
	}
	public void setPersonalMailAutograph(PersonalMailAutograph personalMailAutograph) {
		this.personalMailAutograph = personalMailAutograph;
	}
	public PersonalMailAutographService getPersonalMailAutographService() {
		return personalMailAutographService;
	}
	public void setPersonalMailAutographService(
			PersonalMailAutographService personalMailAutographService) {
		this.personalMailAutographService = personalMailAutographService;
	}
	@Action("listPersonalMailAutograph")
	public String listPersonalMailAutograph(){
		DetachedCriteria criteria=this.getPaginationHelper().createQuery(PersonalMailAutograph.class);
		pagination=this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getPersonalMailAutographService().listByPage(criteria, pagination));
		return SUCCESS;
	}
	@Action("editPersonalMailAutograph")
	public String editPersonalMailAutograph(){
		if (ids!=null) {
			this.personalMailAutograph=this.getPersonalMailAutographService().get(ids[0]);
		}
		return SUCCESS;
	}
	@Action(value = "savePersonalMailAutograph", results = {
			@Result(name = "success", type = "redirect", location = "listPersonalMailAutograph"),
			@Result(name = "error", type = "chain", location = "editPersonalMailAutograph") })
	public String savePersonalMailAutograph(){
		if (personalMailAutograph.getId()==null) {
			this.getPersonalMailAutographService().save(personalMailAutograph);
		}else{
			this.getPersonalMailAutographService().submit(personalMailAutograph);
		}
		return SUCCESS;
	}
	@Action(value = "removePersonalMailAutograph", results = {
			@Result(name = "success", type = "redirect", location = "listPersonalMailAutograph"),
			@Result(name = "error", type = "chain", location = "listPersonalMailAutograph") })
	public String removePersonalMailAutograph(){
		if (ids!=null) {
			this.personalMailAutograph=this.getPersonalMailAutographService().get(ids[0]);
		}
		this.getPersonalMailAutographService().batchRemove(ids);
		return SUCCESS;
	}
}
